package com.UBC417.termproject.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@SuppressWarnings("serial")
public class PageDirectServlet extends HttpServlet{
	private static final Logger log = Logger.getLogger(SubscribeServlet.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		
		String page = req.getParameter("page");
		String forwardTo="";
		// Log out ...		
		if (page.equals("logout")){
			//close session
			HttpSession session = req.getSession();
			session.invalidate();
			
			forwardTo= "/account.jsp";
			
		}else if (page.equals("signin")){
			forwardTo= "/account.jsp";
			
		}else if (page.equals("rating")){
			forwardTo= "/rating.jsp";
			
		}else if (page.equals("monitor")){
			forwardTo= "/monitor.jsp";
			
		}else{
			forwardTo="/account.jsp";
		}
			
		
		// redirect to account page
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher(forwardTo);
		rd.forward(req, resp);
	}	
	
}